// 将路由守卫单独封装
import router from './router'

import store from './store'

const whiltList = ['/reg', '/login']
router.beforeEach((to, from, next) => {
  // console.log('去哪儿',to.path);
  // console.log('来自哪儿', from.path);
  // next()
  const token = store.state.token
  if (token) {
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (whiltList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})